package com.woniuxy.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitmqConfig {
    //延迟队列
    @Bean
    public Queue delayQueue(){
        return new Queue("delayQueue");
    }

    @Bean
    public Queue addOrderQueue() {
        return new Queue("addOrderQueue");
    }
    @Bean
    public Queue addOrderItemQueue() {
        return new Queue("addOrderItemQueue");
    }
    //添加日志队列
    @Bean
    public Queue addLogQueue() {
        return new Queue("addLogQueue");
    }

    //添加用药明细队列
    @Bean
    public Queue addDrugItemsQueue() {
        return new Queue("addDrugItemsQueue");
    }

    //添加排班
    @Bean
    public Queue addScheduleQueue(){
        return new Queue("addScheduleQueue");
    }
    //添加病房和病床
    @Bean Queue addWardQueue(){
        return new Queue("addWardQueue");
    }

    @Bean
    public CustomExchange delayExchange(){
        Map map = new HashMap();
        //指定交换机类型
        map.put("x-delayed-type","direct");
        return new CustomExchange("delayExchange","x-delayed-message",
                true,false,map);
    }

    //绑定
    @Bean
    public Binding delayQueueToDelayExchange(Queue delayQueue,CustomExchange delayExchange){
        return BindingBuilder.bind(delayQueue).to(delayExchange).with("delayRs").noargs();

    }

    //绑定添加日志队列
    @Bean
    public Binding addLogQueueToDelayExchange(Queue addLogQueue,CustomExchange delayExchange){
        return BindingBuilder.bind(addLogQueue).to(delayExchange).with("addLogQueue").noargs();

    }
    //绑定用药明细队列
    @Bean
    public Binding addDrugItemsQueueToDelayExchange(Queue addDrugItemsQueue,CustomExchange delayExchange){
        return BindingBuilder.bind(addDrugItemsQueue).to(delayExchange).with("addDrugItemsQueue").noargs();

    }
    @Bean
    public Binding addScheduleQueueToDelayExchange(Queue addScheduleQueue,CustomExchange delayExchange){
        return BindingBuilder.bind(addScheduleQueue).to(delayExchange).with("addSchedule").noargs();
    }

    @Bean
    public Binding addWardQueueToDelayExchange(Queue addWardQueue,CustomExchange delayExchange){
        return BindingBuilder.bind(addWardQueue).to(delayExchange).with("addWard").noargs();
    }




}
